import pool_util from "./pool_util";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;


var ParticleG = cc.Class({
    name:'ParticleG',
    properties: {
        name:'',
        initPollCount:0,
        prefab:cc.Prefab,
    }
});


export enum ParticleName{
    Bomb1="particle_bomb1"
}


@ccclass
export default class ParticleGroup extends cc.Component {

    @property({type:ParticleG})
    particleG=[];

    particleGindexs={};

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        pool_util.batchInitObjPool(this,this.particleG);
        this.particleG.map((particle,index)=>{
            this.particleGindexs[particle.name]=index;
        });
     }

    start () {

    }

    died(node){
        pool_util.backObjPool(this,node);
    }
 

    getNewNode(ParticleName){
        var poolName = this.particleG[this.particleGindexs[ParticleName]].name + 'Pool';
        var newNode = pool_util.genNewNode(this[poolName],this.particleG[this.particleGindexs[ParticleName]].prefab,this.node);
        newNode.getComponent("particle").init();
        return newNode;
    }

    // update (dt) {}
}
